package wang.lcs.pay.ali;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.domain.AlipayTradeQueryModel;
import com.alipay.api.request.AlipayTradeQueryRequest;
import com.alipay.api.response.AlipayTradeQueryResponse;

@Controller
@RequestMapping("/ali")
public class AliQueryOrderController {

    @Resource
    AlipayClient client;

    @RequestMapping("/query")
    @ResponseBody
    public String queryOrder(@RequestParam("out_trade_no") String thisNo, @RequestParam("trade_no") String aliNo) throws AlipayApiException {

        AlipayTradeQueryRequest alipay_request = new AlipayTradeQueryRequest();
        AlipayTradeQueryModel model = new AlipayTradeQueryModel();
        model.setOutTradeNo(thisNo);
        model.setTradeNo(aliNo);
        alipay_request.setBizModel(model);

        AlipayTradeQueryResponse alipay_response = client.execute(alipay_request);
        return alipay_response.getBody();
    }
}
